//
//  MPNavigationController.swift
//  Whiteboard
//
//  Created by point on 2018/1/4.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

class MPNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
    
   override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
    if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if let vc = (viewController as? BaseViewController){
                var title = "返回"
                if children.count == 1 {
                    title =  "返回" //childViewControllers.first?.title ??
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack:true)
            }
        }
        super.pushViewController(viewController, animated:true)
    }
    
    @objc private func popToParent(){
        popViewController(animated: true)
    }

}

extension UIViewController {
    
    //        navigationBar.barTintColor = UIColor(hex:"#18bdfe")
    //        UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font:UIFont(name: "PingFang-SC-Medium", size: 17)! as Any]
    //        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    
    //    func customBackButton() {
    //        let image = UIImage.icon(from: kIcon_back, color: UIColor.white, imageSize: CGSize(width: 20, height: 30))
    //        let button = UIButton(type: .custom)
    //        button.setImage(image, for: UIControlState.normal)
    //        button.imageEdgeInsets = UIEdgeInsetsMake(5, -30, 0, 0)
    //        button.addTarget(self, action: #selector(backAction), for: UIControlEvents.touchUpInside)
    //        button.frame = CGRect(x: 0, y: 0, width: 45, height: 35)
    //        let buttonItem = UIBarButtonItem(customView: button)
    //        self.navigationItem.leftBarButtonItem = buttonItem
    //    }
    //
    //    @objc func backAction() {
    //        self.navigationController?.popViewController(animated: true);
    //    }
}


